<?php
declare (strict_types = 1);

namespace app\middleware;
use thans\jwt\exception\JWTException;
use thans\jwt\facade\JWTAuth;
use think\Request;
class AdminAuth
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle(Request $request, \Closure $next)
    {

        try {
            $user = JWTAuth::auth();

            if($user){
                $request->user = ['user_id'=>1];

            }else{
                return errMsg(2004 , 'token失效');
            }
        }catch (JWTException $e){
            return errMsg(2004 , 'token失效');
        }

        return $next($request);
    }
}
